//
//  FoodDetailTableViewCell.m
//  示例文件
//
//  Created by dix on 2017/1/4.
//  Copyright © 2017年 dix. All rights reserved.
//

#import "FoodDetailTableViewCell.h"
#import "FoodDetailModel.h"
#import "UIImageView+WebCache.h"
#import "Masonry.h"
@interface FoodDetailTableViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imgView;
@property (weak, nonatomic) IBOutlet UIImageView *pre_imgView;

@property (weak, nonatomic) IBOutlet UIImageView *pre_imgsView;
@property (weak, nonatomic) IBOutlet UILabel *specificsLabel;
@property (weak, nonatomic) IBOutlet UILabel *partner_priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *market_price;
@property (weak, nonatomic) IBOutlet UILabel *numberLabel;
@property (weak, nonatomic) IBOutlet UIButton *reduceBtn;
@property (weak, nonatomic) IBOutlet UIButton *increaseBtn;
@property (weak, nonatomic) IBOutlet UILabel *label;

@end
@implementation FoodDetailTableViewCell

- (IBAction)reduceBtnClick:(id)sender {
    _detailModel.goodNumbers -= 1;
    self.numberLabel.text = [NSString stringWithFormat:@"%ld",(long)_detailModel.goodNumbers];
    if (_detailModel.goodNumbers == 0) {
        self.numberLabel.hidden = YES;
        self.reduceBtn.hidden = YES;
    }
}
- (IBAction)increaseBtnClick:(id)sender {
        self.numberLabel.hidden = NO;
        self.reduceBtn.hidden = NO;
        _detailModel.goodNumbers += 1;
        self.numberLabel.text = [NSString stringWithFormat:@"%ld",(long)_detailModel.goodNumbers];
    //判断
    if ([self.delegate respondsToSelector:@selector(foodDetailTableViewCell:withImageView:)]) {
        [self.delegate foodDetailTableViewCell:self withImageView:self.imgView];
    }
}
- (void)setDetailModel:(FoodDetailModel *)detailModel{
    _detailModel = detailModel;
    self.numberLabel.text = @(_detailModel.goodNumbers).description;
    if (_detailModel.goodNumbers == 0) {
        self.numberLabel.hidden = YES;
        self.reduceBtn.hidden = YES;
    }else{
        self.numberLabel.hidden = NO;
        self.reduceBtn.hidden = NO;

    }
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:detailModel.img] placeholderImage:[UIImage imageNamed:@"v2_placeholder_square"]];
    [self.pre_imgView sd_setImageWithURL:[NSURL URLWithString:detailModel.pre_img] placeholderImage:[UIImage imageNamed:@"jingxuan.png"]];
    [self.pre_imgsView sd_setImageWithURL:[NSURL URLWithString:detailModel.pre_imgs] placeholderImage:[UIImage imageNamed:@"buyOne.png"]];
    if ([detailModel.pm_desc isEqualToString:@"买一赠一"]) {
        self.pre_imgsView.hidden = NO;
    }else{
    
        self.pre_imgsView.hidden = YES;
        
    }
    if ([detailModel.number isEqualToString:@"0"]) {
        self.increaseBtn.hidden = YES;
        self.label.hidden = NO;
    }else{
        self.increaseBtn.hidden = NO;
        self.label.hidden = YES;
    }
    self.nameLabel.text = detailModel.name;
    self.specificsLabel.text = detailModel.specifics;
    self.partner_priceLabel.text = [NSString stringWithFormat:@"$%@",detailModel.partner_price];

    self.market_price.text =[NSString stringWithFormat:@"$%@",detailModel.market_price];
    
    



}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
